/******************** (C) COPYRIGHT 2010 NXP Semiconductors************
* File Name          : main.c
* Author             : NXP Semiconductors
* Date First Issued  : 01/18/2010
* Description        : Main program body.
*******************************************************************************
*******************************************************************************
* History:
* 01/18/2010		 : V1.0		   initial version
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "LPC11xx.h"                        /* LPC11xx definitions */
#include "uart.h"
#include "main.h"

/** @addtogroup All_LPC1300_test_Example
  * @{
  */

/** @addtogroup All_LPC1300_test_Example
  * @{
  */ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ 
extern volatile uint32_t UARTCount;
extern volatile uint8_t UARTBuffer[BUFSIZE];
  
/* Private function prototypes -----------------------------------------------*/   

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  UART_GetKey program.
  * @param  None
  * @retval the Key received from the UART.
  */
uint8_t UART_GetKey(void)
{
  while ( UARTCount == 0 );

  LPC_UART->IER = IER_THRE | IER_RLS;			/* Disable RBR */
  UARTSend( (uint8_t *)UARTBuffer, UARTCount );
  UARTCount = 0;
  LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */

  return UARTBuffer[0];
}	

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t key;

  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();

  /* NVIC is installed inside UARTInit file. */
  UARTInit(115200);  

  /* Display example info  */
  printf(menu);  	  

  while (1)
  {
    key = UART_GetKey();
    switch (key)
    {
	  case '0':						  
	    {
		  LED_main();				  /* LED Blinky test */	
		  break;
		}

      case '1':
	    { 
		  UART_main();				  /* UART Send and receive test */
		  break;
	    }
	
	  case '2':
	    {
		  TemSensor_main();           /* I2C Temperature Sensor test */
		  break;
	    }		  
    } 
  }
}  

/**
  * @}
  */ 

/**
  * @}
  */ 

/************* (C) COPYRIGHT 2010 NXP Semiconductors*****END OF FILE****/
